//
//  Complex.hpp
//  myapp
//
//  Created by nilyang on 2021/3/22.
//

#ifndef Complex_hpp
#define Complex_hpp

#include <complex>
#include <iostream>

class Complex;
Complex& __doapl(Complex*, const Complex&);
Complex& __doaml(Complex*, const Complex&);
Complex& __doami(Complex*, const Complex&);

class Complex {
public:
    Complex(double re = 0, double im = 0);
    Complex(const Complex& rhs);
    Complex& operator=(const Complex& rhs);
    Complex(Complex&& rhs);
    Complex& operator=(Complex&& rhs);

    double real() const { return real_; }
    double imag() const { return imag_; }
    // +=
    Complex& operator+=(const Complex&);
    // -=
    Complex& operator-=(const Complex&);
    // *=
    Complex& operator*=(const Complex&);
    // +complex
    Complex& operator+() { return *this; }
    // -complex
    Complex operator-() { return Complex(-real_, -imag_); }

    // 友元函数
    friend Complex& __doapl(Complex*, const Complex&);
    friend Complex& __doaml(Complex*, const Complex&);
    friend Complex& __doami(Complex*, const Complex&);

private:
    double real_;
    double imag_;
};

double real(const Complex& ths);
double imag(const Complex& ths);

Complex operator+(const Complex ths, const Complex rhs);
Complex operator+(const Complex ths, double number);
Complex operator+(double num, const Complex rhs);
Complex operator-(const Complex& ths, const Complex& rhs);

std::ostream& operator<<(std::ostream& os, const Complex& rhs);

#endif /* Complex_hpp */
